package demo1;

import java.util.Scanner;

/**
 * @Author liangzai
 * @Description:
 */
class User{
    private String name = "liangzai";
    private String password = "lzlwkx0331";


    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public void login(String name,String password){
        if(!this.name.equals(name)){
            throw new NameException();

        }
        if(!this.password.equals(password)){
            throw new PasswordException();
        }
        System.out.println("登陆成功！");
    }

}

public class Test {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        User user = new User();
        String name = scanner.nextLine();
        String password = scanner.nextLine();
        try {
            user.login(name, password);
        }catch (NameException e){
            System.out.println("用户名错误！");
            name = scanner.nextLine();

        }catch (PasswordException e){
            System.out.println("用户名密码错误！");
            password = scanner.nextLine();
            user.login(name, password);
        }finally {

        }
    }
}
